/**
 * 计算反色,
 * @param {*} a 色值
 * @param {*} ilighten 减弱对比度(-1 ~ -15)
 * @returns
 * 示例: oppositeColor("#000000", -4); 返回: #bbbbbb
 */
export const oppositeColor = (a, ilighten) => {
  a = a.replace("#", "");
  //var max16 = 15;
  var max16 = Math.floor(15 + (ilighten || 0));
  if (max16 < 0 || max16 > 15) max16 = 15;

  var c16,
    c10,
    b = [];

  for (var i = 0; i < a.length; i++) {
    c16 = parseInt(a.charAt(i), 16); // to 16进制
    c10 = parseInt(max16 - c16, 10); // 10进制计算
    if (c10 < 0) c10 = Math.abs(c10);
    b.push(c10.toString(16)); // to 16进制
  }
  return "#" + b.join("");
};
